home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / scherz programme / amigaeyes / source / eyes.c next >
C/C++ Source or Header  |  1996-04-07  |  19KB  |  758 lines

  1. /*****************************************************************************/
  2. /*                       AmigaEyes V1.1a (02/12/1994)                        */
  3. /*                                                                           */
  4. /*       Author: Stéphane Poirier                                            */
  5. /*               Copyright © 1994 Stéphane Poirier. All right reserved       */
  6. /*                                                                           */
  7. /*****************************************************************************/
  8.  
  9. /*****************************************************************************/
  10. /*                         Programme principal                               */
  11. /*****************************************************************************/
  12.  
  13. #include <libraries/commodities.h>
  14. #include <exec/types.h>
  15. #include <ctype.h>
  16. #include <intuition/intuition.h>
  17. #include <intuition/intuitionbase.h>
  18. #include <intuition/gadgetclass.h>
  19. #include <libraries/gadtools.h>
  20. #include <clib/exec_protos.h>
  21. #include <clib/intuition_protos.h>
  22. #include <clib/gadtools_protos.h>
  23. #include <clib/graphics_protos.h>
  24. #include <clib/icon_protos.h>
  25. #include <clib/utility_protos.h>
  26. #include <clib/dos_protos.h>
  27. #include <clib/commodities_protos.h>
  28. #include <string.h>
  29. #include <clib/diskfont_protos.h>
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include <exec/memory.h>
  33. #include <workbench/workbench.h>
  34. #include <workbench/startup.h>
  35. #include <time.h>
  36.  
  37. #include "eyes.h"
  38.  
  39. struct parametres Parametres;
  40. unsigned int clockInit[2];
  41. USHORT refresh;
  42.  
  43. extern int EyeCloseWindow(void);
  44. void ToolTypesParameters(struct WBArg *);
  45. void ValeursParDefaut(void);
  46. int EyesInfo(void);
  47. int EyesGoPublic(void);
  48. int AutoJump(void);
  49. void OpenLibs(void);
  50. void CloseLibs(void);
  51. void SortiePropre(void);
  52.  
  53. UBYTE *toolTypes[]=
  54. {
  55.   "AUTOFRONT=ON|OFF",
  56.   "AUTOJUMP=ON|OFF",
  57.   "TIMEOUT=n",
  58.   "BACKGROUND=n",
  59.   "BORDER=n",
  60.   "PUPIL=n",
  61.   "EYELIP=n",
  62.   "WINDOW=n",
  63.   "XPOS=n",
  64.   "YPOS=n",
  65.   "PRIORITY=n",
  66.   "REFRESH=n",
  67.   "CUSTOM_DRAWING",
  68.   "HOTKEY",
  69.   NULL
  70. };
  71.  
  72. struct Library *GfxBase;
  73. struct Library *DosBase;
  74. struct Library *CxBase = NULL;
  75.  
  76. UBYTE hotkey[64] = "alt $";
  77.  
  78. struct Screen    *ActiveScreen;
  79.  
  80. static struct Screen    *Scr         =     NULL;
  81. static UBYTE        *PubScreenName    =    NULL;
  82. static APTR         VisualInfo    =    NULL;
  83. static struct Window    *EyeWnd        =    NULL;
  84. static struct Menu    *EyesMenu    =    NULL;
  85. static struct BitMap     SBitmap;
  86. struct IntuiMessage     EyeMsg;
  87. static struct TextFont    *Font        =    NULL;
  88. static UWORD         EyeLeft    =    530;
  89. static UWORD         EyeTop        =    2;
  90. static UWORD         EyeWidth    =    94;
  91. static char        *Version    =     "$VER: AmigaEyes 1.1a";
  92. static char         PublicName[128];
  93. static char         PublicNameInit[128];
  94.  
  95. BOOL             Restart = TRUE;
  96. BOOL             ModifyPub = FALSE;
  97. struct              Task *task;
  98.  
  99. #ifdef ENTRELACE
  100. static UWORD                  EyeHeight = 40;
  101. #else
  102. static UWORD                  EyeHeight = 23;
  103. #endif
  104.  
  105. /*
  106. ** Titre de la fenêtre
  107. */
  108. static UBYTE                 *EyeWdt = (UBYTE *)"Eyes";
  109.  
  110. /*
  111. ** Définition du menu
  112. */
  113. static struct NewMenu EyesNewMenu[] = {
  114.     NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  115.     NM_ITEM, (STRPTR)"-> Default PubScreen", (STRPTR)"P", 0, NULL, EyesGoPublic,
  116.     NM_ITEM, (STRPTR)"AutoJump", NULL, CHECKIT, NULL, (APTR)AutoJump,
  117.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  118.     NM_ITEM, (STRPTR)"About", (STRPTR)"?", 0, 0L, (APTR)EyesInfo,
  119.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  120.     NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, (APTR)EyeCloseWindow,
  121.     NM_END, NULL, NULL, 0, 0L, NULL };
  122.  
  123. /*****************************************************************************/
  124.  
  125. void errorMessage(STRPTR error)
  126. {
  127. if (error)
  128.     printf("Error: %s\n", error);
  129. }
  130.  
  131. /*****************************************************************************/
  132.  
  133. int SetupScreen( void )
  134. {
  135.   if ( ! ( Scr = LockPubScreen( PubScreenName )))
  136.     return( 1L );
  137.  
  138.   if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  139.     return( 2L );
  140.  
  141.   return( 0L );
  142. }
  143.  
  144. /******************************************************************************/
  145. /* Gestion des évenements Intuition                                           */
  146. /******************************************************************************/
  147. int HandleEyeIDCMP( void )
  148. {
  149.   int      (*func)(void);
  150.   struct MenuItem    *n;
  151.   struct IntuiMessage  *m;
  152.   BOOL      running = TRUE;
  153.  
  154.   while( m = GT_GetIMsg( EyeWnd->UserPort )) {
  155.  
  156.     CopyMem(( char * )m, ( char * )&EyeMsg, (long)sizeof( struct IntuiMessage ));
  157.  
  158.     GT_ReplyIMsg( m );
  159.  
  160.     switch ( EyeMsg.Class ) {
  161.  
  162.       case  IDCMP_REFRESHWINDOW:
  163.         GT_BeginRefresh( EyeWnd );
  164.         GT_EndRefresh( EyeWnd, TRUE );
  165.         break;
  166.  
  167.       case  IDCMP_CLOSEWINDOW:
  168.         running = FALSE;
  169.         Restart = TRUE;
  170.         Dodo = TRUE;
  171.         break;
  172.  
  173.       case  IDCMP_MENUPICK:
  174.         while( EyeMsg.Code != MENUNULL ) {
  175.           n = ItemAddress( EyesMenu, EyeMsg.Code );
  176.           func = (int (*) (void))(GTMENUITEM_USERDATA( n ));
  177.           running = func();
  178.           EyeMsg.Code = n->NextSelect;
  179.         }
  180.         break;
  181.     }
  182.   }
  183.   return( running );
  184. }
  185.  
  186. /******************************************************************************/
  187. /* Ouverture de la fenêtre                                                    */
  188. /******************************************************************************/
  189. int OpenEyeWindow( void )
  190. {
  191.   UWORD    offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  192.  
  193.   if (! ( EyesMenu = CreateMenus( EyesNewMenu, GTMN_FrontPen, 0L, TAG_DONE ))) 
  194.     return(0L);
  195.  
  196.   LayoutMenus( EyesMenu, VisualInfo, TAG_DONE );
  197.  
  198.   if ( ! ( EyeWnd = OpenWindowTags( NULL,
  199.         WA_Left,  EyeLeft,
  200.         WA_Top,    EyeTop,
  201.         WA_Width,  EyeWidth,
  202.         WA_Height,  EyeHeight + offy,
  203.         WA_SuperBitMap, &SBitmap,
  204.         WA_IDCMP,  IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_MOUSEMOVE|IDCMP_MENUPICK,
  205.         WA_Flags,  WFLG_GIMMEZEROZERO|WFLG_DRAGBAR|WFLG_SUPER_BITMAP|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_REPORTMOUSE,
  206.         WA_Title,  EyeWdt,
  207.         WA_NewLookMenus, TRUE,
  208.         WA_ScreenTitle,  "                           Big Brother is watching you !",
  209.         WA_PubScreen,  Scr,
  210.         TAG_DONE )))
  211.   return( 0L );
  212.  
  213.   GT_RefreshWindow( EyeWnd, NULL );
  214.   SetMenuStrip( EyeWnd, EyesMenu );
  215.  
  216.   return( (int)offy );
  217. }
  218.  
  219.  
  220. /******************************************************************************/
  221. /* Sélection de l'option de menu 'AutoJump'                                   */
  222. /******************************************************************************/
  223. void AutoJumpMenu(BOOL CheckMark)
  224. {
  225.   struct MenuItem *Item;
  226.   UWORD Flags;
  227.  
  228.   ClearMenuStrip(EyeWnd);
  229.   Item = EyesMenu->FirstItem->NextItem;
  230.   Flags = Item->Flags;
  231.   
  232.   if (CheckMark)
  233.     Flags |= CHECKED;
  234.  
  235.   Item->Flags = Flags;
  236.  
  237.   ResetMenuStrip(EyeWnd, EyesMenu);
  238. }
  239.  
  240. /******************************************************************************/
  241. /* Change l'état de l'indicateur 'autojump'                                   */
  242. /******************************************************************************/
  243. int AutoJump(void)
  244. {
  245.   if (Parametres.autojump == TRUE)
  246.   {
  247.    Parametres.autojump = FALSE;
  248.   }
  249.   else
  250.   {
  251.     Parametres.autojump = TRUE;
  252.   }
  253.   return(1L);
  254. }
  255.  
  256. /******************************************************************************/
  257. /* Effectue la fonction de saut sur l'écran public actif au cas ou celui-ci   */
  258. /*  a changé.                                                                 */
  259. /******************************************************************************/
  260. int ProcessJump(BOOL Force)
  261. {
  262.   struct List *PubList;
  263.   struct PubScreenNode *PubNode;
  264.   struct Screen *ActiveScr = NULL;
  265.   BOOL Loop = TRUE;
  266.   char ScrName[128];
  267.   BOOL PubOk = FALSE, running = TRUE;
  268.   static UWORD DelaiJump = 0;
  269.   
  270.   if (Force)
  271.   {
  272.     DelaiJump += refresh;
  273.     if (DelaiJump < 50) return (running);
  274.   }
  275.  
  276.   DelaiJump = 0;
  277.   
  278. /*  
  279. ** Récupère l'adresse de l'écran actif (avant plan)
  280. */
  281.   while (ActiveScr == NULL)
  282.   {
  283.     LockIBase(0);
  284.     ActiveScr = ((struct IntuitionBase *)IntuitionBase)->ActiveScreen;
  285.     UnlockIBase(0);
  286.     if (!ActiveScr) Delay(SLEEP);
  287.   }
  288.  
  289.   if (ActiveScreen != ActiveScr)
  290.   {
  291.   /*
  292.   ** Récupère un pointeur sur la liste des écrans publics
  293.   */
  294.     PubList = LockPubScreenList();
  295.     PubNode = (struct PubScreenNode *)PubList->lh_Head;
  296.   
  297.   /*
  298.   ** Recherche à quel écran public correspond l'écran actif
  299.   */
  300.     while (Loop)
  301.     {
  302.       if (PubNode)
  303.       {
  304.         if (ActiveScr == PubNode->psn_Screen)
  305.         {
  306.         /*
  307.         ** On a trouvé !
  308.         */
  309.           Loop = FALSE;
  310.           strcpy(ScrName, PubNode->psn_Node.ln_Name);
  311.           PubOk = TRUE;
  312.         }
  313.       }
  314.       else
  315.       {
  316.         Loop = FALSE;
  317.       }
  318.   
  319.       if (Loop) PubNode = (struct PubScreenNode *)PubNode->psn_Node.ln_Succ;
  320.     }
  321.   
  322.   /*
  323.   ** Libère la liste des écrans publics
  324.   */
  325.     UnlockPubScreenList();
  326.  
  327.   /*
  328.   ** Si on a trouvé l'écran public...
  329.   */
  330.     if (PubOk)
  331.   
  332.     /*
  333.     ** Si celui-ci n'est pas l'écran actif
  334.     */
  335.       if (strcmp(ScrName, PublicNameInit) !=NULL)
  336.       {
  337.         GetDefaultPubScreen(PublicName);
  338.         SetDefaultPubScreen(ScrName);
  339.         Restart = TRUE;
  340.         ModifyPub = TRUE;
  341.         EyeCloseWindow();
  342.         running = FALSE;
  343.         Dodo = FALSE;
  344.         strcpy(PublicNameInit, ScrName);
  345.         ActiveScreen = ActiveScr;
  346.       }    
  347.   }
  348.   
  349.     return (running);
  350. }  
  351. /*****************************************************************************/
  352. int ProcessActive(void)
  353. {
  354.   struct List *PubList;
  355.   struct PubScreenNode *PubNode;
  356.   struct Screen *ActiveScr;
  357.   BOOL Loop = TRUE;
  358.   char ScrName[128];
  359.   BOOL PubOk = FALSE, running = TRUE;
  360.   
  361.   LockIBase(0);
  362.   ActiveScr = ((struct IntuitionBase *)IntuitionBase)->ActiveScreen;
  363.   UnlockIBase(0);
  364.  
  365.   PubList = LockPubScreenList();
  366.   PubNode = (struct PubScreenNode *)PubList->lh_Head;
  367.  
  368.   while (Loop)
  369.   {
  370.     if (PubNode)
  371.     {
  372.       if (ActiveScr == PubNode->psn_Screen)
  373.       {
  374.         Loop = FALSE;
  375.         strcpy(ScrName, PubNode->psn_Node.ln_Name);
  376.         PubOk = TRUE;
  377.       }
  378.     }
  379.     else
  380.     {
  381.       Loop = FALSE;
  382.     }
  383.  
  384.     if (Loop) PubNode = (struct PubScreenNode *)PubNode->psn_Node.ln_Succ;
  385.   }
  386.  
  387.   UnlockPubScreenList();
  388.  
  389.   if (PubOk)
  390.   {
  391.     GetDefaultPubScreen(PublicName);
  392.     SetDefaultPubScreen(ScrName);
  393.     Restart = TRUE;
  394.     ModifyPub = TRUE;
  395.     EyeCloseWindow();
  396.     running = FALSE;
  397.     strcpy(PublicNameInit, ScrName);
  398.   }    
  399.  
  400.   return (running);
  401. }
  402.  
  403.  
  404. /*****************************************************************************/
  405.  
  406. void main(int argc, char **argv)
  407. {
  408.   struct WBArg *wbarg;
  409.  
  410.   struct WBStartup *WBenchMsg;
  411.  
  412.   LONG i;
  413.   int ret, offy, depth;
  414.   BOOL running;
  415.   BOOL reveil;
  416.  
  417.   OpenLibs();
  418.   ValeursParDefaut();                /* Valeurs par défaut */
  419.  
  420.   WBenchMsg = (struct WBStartup *)argv;     /* Arguments du Wb */
  421.   wbarg = WBenchMsg->sm_ArgList;
  422.  
  423.   for(i = 0; i < WBenchMsg->sm_NumArgs; i++, wbarg++)
  424.     ToolTypesParameters(wbarg);        /* ToolTypes ! */
  425.  
  426.   StartCommodity();
  427.  
  428.   while (Restart)
  429.   {
  430.   /*
  431.   ** Attend un peu, le temps que l'écran public soit bien en place
  432.   */
  433.     Delay(SLEEP);
  434.  
  435.     running = TRUE;
  436.     GetDefaultPubScreen(PublicNameInit);
  437.     
  438.     if ((ret = SetupScreen()) == NULL)
  439.     {
  440.       if (ModifyPub)
  441.       {
  442.         SetDefaultPubScreen(PublicName);
  443.         ModifyPub = FALSE;
  444.       }
  445.       
  446.       ret = timer(clockInit);            /* initialise l'horloge */
  447.  
  448.       depth = Scr->RastPort.BitMap->Depth;    /* Initialise ma... */
  449.       InitBitMap(&SBitmap, depth, WNDX, WNDY);    /* superbitmap */
  450.       for (i = 0; i < depth; i++)
  451.         if((SBitmap.Planes[i] = AllocRaster(WNDX, WNDY)) == NULL)
  452.           printf("erreur\n");
  453.           
  454.       if ((offy = OpenEyeWindow()) != NULL)    /* Initialise ma fenêtre */
  455.       {
  456.         if (Parametres.autojump) AutoJumpMenu(TRUE);
  457.  
  458.         InitEyes(EyeWnd,&SBitmap);
  459.         InitPlot(EyeWnd,&SBitmap);
  460.         reveil = DrawingEyes(EyeWnd, &SBitmap, offy);
  461.         Restart = FALSE;
  462.         while (running == TRUE)
  463.         {
  464.           Delay (refresh);
  465.           running = HandleEyeIDCMP();
  466.           reveil = DrawingEyes(EyeWnd, &SBitmap, offy);
  467.           
  468.           if (running)
  469.           {
  470.             running = ProcessMsg();
  471.             if (running)
  472.             {
  473.               if ((reveil) && (Parametres.autofront))
  474.               {
  475.                 WindowToFront(EyeWnd);
  476.               }
  477.               if (Parametres.autojump)
  478.               {
  479.                 running = ProcessJump(TRUE);
  480.               }
  481.             }
  482.           }
  483.         }
  484.         EyeLeft = EyeWnd->LeftEdge;
  485.         EyeTop  = EyeWnd->TopEdge;
  486.  
  487.         CloseEyeWindow();
  488.         CloseDownScreen(); 
  489.         for (i = 0; i < depth; i++)
  490.           FreeRaster(SBitmap.Planes[i],WNDX, WNDY);
  491.       }
  492.       else printf("erreur window\n");
  493.     } 
  494.     else printf("erreur screen\n");
  495.     
  496.     while (Dodo)
  497.     {
  498.       if (Parametres.autojump)
  499.       {
  500.         ProcessJump(TRUE);
  501.       }
  502.       else
  503.         Wait(sigflags);
  504.  
  505.       ProcessMsg();
  506.     }
  507.   }
  508.   SortiePropre();  
  509. }
  510.  
  511. /*****************************************************************************/
  512. int EyesInfo(void)
  513. {
  514.   struct IntuiMessage *m;
  515.   
  516.   struct EasyStruct About = 
  517.   {
  518.     sizeof(struct EasyStruct),
  519.     0,
  520.     "AmigaEyes ",
  521.     "   AmigaEyes 1.1 (08/11/1994)\n\n"
  522.     "     © 1994  Stéphane Poirier\n"
  523.     "E-mail: poiries@asterix.saclay.cea.fr\n\n"
  524.     "Hot Key = < %s >\n\n"
  525.     "This Program is freeware",
  526.     "Ok"
  527.   };
  528.   
  529.   EasyRequest(EyeWnd, &About, 0, hotkey);
  530.  
  531.   while( m = GT_GetIMsg( EyeWnd->UserPort )) GT_ReplyIMsg( m );
  532.   return(1L);
  533. }
  534.  
  535. /*****************************************************************************/
  536. int EyesGoPublic(void)
  537. {
  538.   EyeCloseWindow();
  539.   Restart = TRUE;
  540.   return(FALSE);
  541. }
  542.  
  543. /*****************************************************************************/
  544. /*                       Traitement des ToolTypes                            */
  545. /*****************************************************************************/
  546.  
  547. void ToolTypesParameters(struct WBArg *wbarg)
  548. {
  549.   struct DiskObject *dobj;
  550.   char **toolarray;
  551.   char *s;
  552.   UBYTE ancpriorite;
  553.   
  554.   task = FindTask(NULL);
  555.  
  556.   if((*wbarg->wa_Name) && (dobj = GetDiskObject(wbarg->wa_Name)))
  557.   {
  558.     toolarray = (char **)dobj->do_ToolTypes;
  559.     
  560.     if (s = (char *)FindToolType(toolarray,"AUTOFRONT"))
  561.     {
  562.       if(MatchToolValue(s,"ON"))
  563.         Parametres.autofront = TRUE;
  564.       if(MatchToolValue(s,"OFF"))
  565.         Parametres.autofront = FALSE;
  566.      }
  567.  
  568.     if (s = (char *)FindToolType(toolarray,"TIMEOUT"))
  569.     {
  570.         if (isalnum(*s))
  571.           Parametres.timeout = (atoi(s));
  572.      }
  573.     if (s = (char *)FindToolType(toolarray,"BACKGROUND"))
  574.     {
  575.         if (isalnum(*s))
  576.           Parametres.fond = (atoi(s));
  577.      }
  578.     if (s = (char *)FindToolType(toolarray,"BORDER"))
  579.     {
  580.         if (isalnum(*s))
  581.           Parametres.bord = (atoi(s));
  582.      }
  583.     if (s = (char *)FindToolType(toolarray,"PUPIL"))
  584.     {
  585.         if (isalnum(*s))
  586.           Parametres.pupille = (atoi(s));
  587.      }
  588.     if (s = (char *)FindToolType(toolarray,"EYELIP"))
  589.     {
  590.         if (isalnum(*s))
  591.           Parametres.paupiere = (atoi(s));
  592.      }
  593.     if (s = (char *)FindToolType(toolarray,"WINDOW"))
  594.     {
  595.         if (isalnum(*s))
  596.           Parametres.fenetre = (atoi(s));
  597.      }
  598.     if (s = (char *)FindToolType(toolarray,"XPOS"))
  599.     {
  600.         if (isalnum(*s))
  601.           EyeLeft = (atoi(s));
  602.      }
  603.     if (s = (char *)FindToolType(toolarray,"YPOS"))
  604.     {
  605.         if (isalnum(*s))
  606.           EyeTop = (atoi(s));
  607.      }
  608.     if (s = (char *)FindToolType(toolarray,"PRIORITY"))
  609.     {
  610.         if ((isalnum(*s)) || ((*s) = '-') || ((*s) = '+'))
  611.         {
  612.           ancpriorite = SetTaskPri(task,atoi(s));
  613.           Parametres.priorite = atoi(s);
  614.         /*
  615.         ** Because of a small bug in AutoJump mode, priorite must be >= -1
  616.         */
  617.           if (Parametres.priorite < -1) Parametres.priorite = -1;
  618.         }
  619.      }
  620.     if (s = (char *)FindToolType(toolarray,"REFRESH"))
  621.     {
  622.         if (isalnum(*s))
  623.           Parametres.refresh = (atoi(s));
  624.      }
  625.     if (s = (char *)FindToolType(toolarray,"CUSTOM_DRAWING"))
  626.     {
  627.           Parametres.drawing = CUSTOM_DRAW;
  628.      }
  629.     if (s = (char *)FindToolType(toolarray,"HOTKEY"))
  630.     {
  631.           strcpy(hotkey, s);
  632.      }
  633.     if (s = (char *)FindToolType(toolarray,"AUTOJUMP"))
  634.     {
  635.       if(MatchToolValue(s,"ON"))
  636.         Parametres.autojump = TRUE;
  637.       if(MatchToolValue(s,"OFF"))
  638.         Parametres.autojump = FALSE;
  639.      }
  640.        
  641.     FreeDiskObject(dobj);
  642.   }
  643. }
  644.  
  645. /*****************************************************************************/
  646.  
  647. void ValeursParDefaut(void)
  648. {
  649.   Parametres.autofront = FALSE;
  650.   Parametres.autojump = FALSE;
  651.   Parametres.timeout = 30;
  652.   Parametres.pupille = 1;
  653.   Parametres.bord = 1;
  654.   Parametres.fond = 2;
  655.   Parametres.paupiere = 3;
  656.   Parametres.fenetre = 0;
  657.   Parametres.refresh = 2;
  658.   Parametres.priorite = 0;
  659.   Parametres.drawing = STANDARD_DRAW;
  660.   refresh = SLEEP;
  661. }
  662.  
  663. /*****************************************************************************/
  664.  
  665. void OpenLibs(void)
  666. {
  667.   if (NULL == (DosBase = OpenLibrary("dos.library", 37)))
  668.   {
  669.     errorMessage( "Requires at least V37 dos.library");
  670.     SortiePropre();
  671.   }
  672.  
  673.   if (NULL == (IntuitionBase = OpenLibrary("intuition.library", 37)))
  674.   {
  675.     errorMessage( "Requires at least V37 intuition.library");
  676.     SortiePropre();
  677.   }
  678.  
  679.   if (NULL == (GfxBase = OpenLibrary("graphics.library", 37)))
  680.   {
  681.     errorMessage( "Requires at least V37 graphics.library");
  682.     SortiePropre();
  683.   }
  684.  
  685.   if (NULL == (GadToolsBase = OpenLibrary("gadtools.library", 37)))
  686.   {
  687.      errorMessage( "Requires at least V37 gadtools.library");
  688.      SortiePropre();
  689.   }
  690.  
  691.   if (NULL == (CxBase = OpenLibrary("commodities.library", 37)))
  692.   {
  693.      errorMessage( "Requires at least V37 commodities.library");
  694.      SortiePropre();
  695.   }
  696. }
  697.  
  698. /*****************************************************************************/
  699. void CloseLibs(void)
  700. {
  701.   if (GfxBase)         CloseLibrary(GfxBase);
  702.   if (IntuitionBase)    CloseLibrary(IntuitionBase);
  703.   if (CxBase)        CloseLibrary(CxBase);
  704.   if (DosBase)        CloseLibrary(DosBase);
  705.   if (GadToolsBase)    CloseLibrary(GadToolsBase);
  706.  
  707. /*****************************************************************************/
  708.  
  709. void CloseDownScreen( void )
  710. {
  711.   if ( VisualInfo ) {
  712.     FreeVisualInfo( VisualInfo );
  713.     VisualInfo = NULL;
  714.   }
  715.  
  716.   if ( Scr        ) {
  717.     UnlockPubScreen( NULL, Scr );
  718.     Scr = NULL;
  719.   }
  720.  
  721.   if ( Font       ) {
  722.     CloseFont( Font );
  723.     Font = NULL;
  724.   }
  725. }
  726.  
  727. /*****************************************************************************/
  728.  
  729. void CloseEyeWindow( void )
  730. {
  731.   if ( EyeWnd        ) {
  732.     ClearMenuStrip( EyeWnd );
  733.     CloseWindow( EyeWnd );
  734.     EyeWnd = NULL;
  735.   }
  736. }
  737.  
  738. /*****************************************************************************/
  739.  
  740. void SortiePropre(void)
  741. {
  742.   CloseEyeWindow();
  743.   CloseDownScreen();
  744.  
  745.   if (EyesBroker) DeleteCxObjAll(EyesBroker);
  746.   if (EyesBrokerMsgPort)
  747.   {
  748.     while(MsgBroker = (CxMsg *)GetMsg(EyesBrokerMsgPort))
  749.     {
  750.       ReplyMsg((struct Message *)MsgBroker);
  751.     }
  752.     DeleteMsgPort(EyesBrokerMsgPort);
  753.   }
  754.  
  755.   CloseLibs();
  756.   exit(0);
  757. }